// pages/comment/comment.js
Page({
  data: {
    uid: '',
    oid: '',
    image: '',
    comment: '',
    round: [{}, {}, {}, {}, {}],
    article: 0,
    acceptshop: '',
    name: '',
    imgUrl: '',
    data: null,
    num:'',
    display:"block"
  },
  onLoad: function (options) {
    // 页面初始化 options为页面跳转所带来的参数
    var that = this;
    that.setData({
      uid: options.uid,
      oid: options.oid,
      image: options.image,
      acceptshop: options.acceptshop
    })
    wx.getStorage({
      key: 'userInfo',
      success: function (res) {
        // success
        that.setData({
          imgUrl: res.data.headImg,
          name: res.data.nickname
        })
      },
    })
    wx.request({
      url: "http://1.aiym.applinzi.com/aiyouwai.php",
      data: {
        type: "getComment",
        paras: {
          oid: options.oid,
        }
      },
      header: { "content-type": "application/json" },
      success: function (res) {
        console.log(res)
     if(res.data){
       that.setData({
          data: res.data,
          num:res.data.length
        })
    } 
      }
    })
  },
  comment: function (e) {
    this.setData({
      comment: e.detail.value
    })
  },
  // 点击设置星评评
  click: function (e) {
    this.setData({
      article: e.currentTarget.dataset.index + 1
    })
  },
  more:function(){
    this.setData({
      display:'none'
    })
  },
  // 点击提交评论
  submit: function () {
    var that = this;
    wx.request({
      url: "http://1.aiym.applinzi.com/aiyouwai.php",
      data: {
        type: "putComment",
        paras: {
          uid: this.data.uid,
          oid: this.data.oid,
          shopID: this.data.acceptshop,
          content: this.data.comment,
          stars: this.data.article
        }
      },
      header: { "content-type": "application/json" },
      success: function (res) {
         wx.showModal({
        content: '评论成功',
        showCancel: false,
        success: function (res) {
         wx.navigateBack({
           delta: 1, // 回退前 delta(默认为1) 页面
         })
        }
      });
      }
    })
  }
})


